package com.example.lvsuo.controller;


import com.example.lvsuo.entity.HrTeam;
import com.example.lvsuo.entity.RecordDocument;
import com.example.lvsuo.entity.vo.RecordDocumentVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.IRecordDocumentService;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 收入凭单表 前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/recordDocument")
public class RecordDocumentController {

    @Autowired
    IRecordDocumentService iRecordDocumentService;

    /**
     * 高级查询+分页
     * @param recordDocumentVo
     * @return
     */
    @GetMapping
    public Result getRecordDocument(RecordDocumentVo recordDocumentVo){
        PageHelper.startPage(recordDocumentVo.getPageId(),recordDocumentVo.getPageNum());
        PageInfo pageInfo = new PageInfo(iRecordDocumentService.getRecordDocument(recordDocumentVo));
        return Result.back("ok","200",pageInfo);
    }

    /**
     * 高级查询+分页+当前登录者
     * @param recordDocumentVo
     * @return
     */
    @GetMapping(params = "chaxun=1")
    public Result getRecordDocumentName(RecordDocumentVo recordDocumentVo){
        System.out.println("查询为"+recordDocumentVo);
        PageHelper.startPage(recordDocumentVo.getPageId(),recordDocumentVo.getPageNum());
        List<RecordDocumentVo> recordDocumentName = iRecordDocumentService.getRecordDocumentName(recordDocumentVo);
        PageInfo pageInfo = new PageInfo(recordDocumentName);
        return Result.back("ok","200",pageInfo);
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getRecordDocumentId(@PathVariable String id){
        List<RecordDocumentVo> list = iRecordDocumentService.getRecordDocumentId(id);
        return Result.back("ok", "200", list);
    }

    /**
     * 添加
     *
     * @param recordDocument
     * @return
     */
    @PostMapping
    Result addRecordDocument(@RequestBody RecordDocument recordDocument) {
        System.out.println(recordDocument);
        iRecordDocumentService.save(recordDocument);
        return Result.back("ok", "200");
    }

    /**
     * 修改
     *
     * @param recordDocument
     * @return
     */
    @PutMapping
    Result updateRecordDocument(@RequestBody RecordDocument recordDocument) {
        System.out.println(recordDocument);
        iRecordDocumentService.updateById(recordDocument);//添加用户
        return Result.back("ok", "200");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteRecordDocument(@PathVariable String id){
        iRecordDocumentService.removeById(id);
        return Result.back("ok","200");
    }


}

